//
//  AY_BookQDHeaderView.m
//  AiYue
//
//  Created by boWen on 2023/11/3.
//

#import "AY_BookQDHeaderView.h"
#import "AY_UseListPage.h"
@interface AY_BookQDHeaderView ()
@property (nonatomic,strong) UIView * bg_View;//底部圆角
@property (nonatomic,strong) UIImageView * jifen_ImgView;
@property (nonatomic,strong) UILabel * jifenLabel;
@property (nonatomic,strong) UILabel * jifenNumLabel;
@property (nonatomic,strong) UIImageView * jinbi_ImgView;
@property (nonatomic,strong) UILabel * yqdLabel;
@property (nonatomic,strong) UIImageView * down_ImgView;

@end

@implementation AY_BookQDHeaderView


- (instancetype)initWithFrame:(CGRect)frame {
    if([super initWithFrame:frame]) {
        [self initWithAllUI];
    }
    return self;
}


- (void)initWithAllUI {
    
    UIView * topView = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor clearColor] andRadius:0 andAddSubView:self];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self);
        make.height.mas_offset(GK_STATUSBAR_NAVBAR_HEIGHT);
    }];
    
   UIButton * backBtn = [AYTool createButtonWithFrame:CGRectZero andTitle:@"" andFont:YFont(10) andTitleColor:COLOR_Bg andBg:nil andImage:YImage(@"AY_nav_pop.png") andBgImage:nil andTarget:self andAction:@selector(popNavAction) andRadius:0 andAddSubView:topView];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(topView).offset(YNUM(-8));
        make.left.equalTo(topView).offset(YNUM(8));
        make.height.width.mas_equalTo(YNUM(24));
    }];
    
    UILabel * qdLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"签到" andTextColor:COLOR(@"#000000") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(18)] andLines:1 andRadius:0 andAddSubView:topView];
    [qdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backBtn);
        make.centerX.equalTo(topView);
        make.height.mas_offset(YNUM(22));
    }];
    
    UIButton *xfBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    [xfBtn setTitle:@"金币记录" forState:UIControlStateNormal];
    [xfBtn setTitleColor:COLOR(@"#F86923") forState:UIControlStateNormal];
    [xfBtn addTarget:self action:@selector(shudouList) forControlEvents:UIControlEventTouchUpInside];
    xfBtn.titleLabel.font = YFont(14);
    [topView addSubview:xfBtn];
    [xfBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(backBtn);
        make.right.equalTo(topView).offset(-YNUM(15));
        make.height.mas_offset(YNUM(22));
        make.width.mas_equalTo(YNUM(100));
    }];
    
    self.bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor clearColor] andRadius:YNUM(1) andAddSubView:self];
    [self.bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self);
        make.top.equalTo(topView.mas_bottom);
    }];
    
    self.jifen_ImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"icon_top_jb.png") andBg:COLOR_Bg andRadius:YNUM(27) andAddSubView:self.bg_View];
    [self.jifen_ImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_offset(YNUM(26));
        make.left.equalTo(self.bg_View).offset(YNUM(14));
        make.top.equalTo(self.bg_View).offset(YNUM(26));
    }];
    
    self.jifenLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"我的积分" andTextColor:COLOR(@"#010101") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(14)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.jifenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.jifen_ImgView);
        make.left.equalTo(self.jifen_ImgView.mas_right).offset(YNUM(2));
        make.height.mas_offset(YNUM(22));
    }];
    
    self.jifenNumLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR(@"#000002") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(46)] andLines:1 andRadius:0 andAddSubView:self.bg_View];
    [self.jifenNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.jifenLabel.mas_bottom).offset(YNUM(8));
        make.left.equalTo(self.jifen_ImgView);
        make.height.mas_offset(YNUM(46));
    }];

    
    self.jinbi_ImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"icon_qd_jinb.png") andBg:[UIColor clearColor] andRadius:0 andAddSubView:self.bg_View];
    [self.jinbi_ImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_offset(YNUM(156));
        make.width.mas_offset(YNUM(144));
        make.right.equalTo(self.bg_View).offset(YNUM(-16));
        make.bottom.equalTo(self.bg_View);
    }];
  
    self.down_ImgView = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"icon_header_top.png") andBg:[UIColor clearColor] andRadius:0 andAddSubView:self.bg_View];
    [self.down_ImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_offset(YNUM(40));
        make.right.equalTo(self.bg_View).offset(YNUM(-16));
        make.left.equalTo(self.bg_View).offset(YNUM(16));
        make.bottom.equalTo(self.bg_View);
    }];
    
    self.yqdLabel = [AYTool createLabelWithFrame:CGRectZero andText:@"" andTextColor:COLOR(@"#010101") andBgColor:nil andFont:[UIFont boldSystemFontOfSize:YNUM(16)] andLines:1 andRadius:0 andAddSubView:self.down_ImgView];
    [self.yqdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.down_ImgView);
        make.left.equalTo(self.down_ImgView).offset(YNUM(12));
        make.height.mas_offset(YNUM(22));
    }];
}


- (void)setSignModel:(SignOwnModel *)signModel {
    _signModel = signModel;
    self.yqdLabel.text = [NSString stringWithFormat:@"已连续签到%@天", kStringUtils(_signModel.signDays)];
    NSString *labelText = self.yqdLabel.text;
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
    NSRange rangeA = [labelText rangeOfString:kStringUtils(_signModel.signDays)];
    [attributedString addAttribute:NSForegroundColorAttributeName value:COLOR(@"#F86923") range:rangeA];
    self.yqdLabel.attributedText = attributedString;
}


- (void)setGoldNum:(NSString *)goldNum {
    self.jifenNumLabel.text = kStringUtils(goldNum);
}


- (void)popNavAction {
    [[AYTool viewControllerWith:self].navigationController popViewControllerAnimated:YES];
}

- (void)shudouList
{
    AY_UseListPage * page = [[AY_UseListPage alloc] init];
    page.logType = consumptionLog_goldBean;
    [[AYTool viewControllerWith:self].navigationController pushViewController:page animated:YES];
}

@end
